<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <!-- 主表单区域 -->
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
      </a-form-model>
    </j-form-container>
    <!-- 子表单区域 -->
    <j-editable-table
      :ref="refKeys[0]"
      :loading="skAreaAcquisitionTimeTable.loading"
      :columns="skAreaAcquisitionTimeTable.columns"
      :dataSource="skAreaAcquisitionTimeTable.dataSource"
      :maxHeight="300"
      :disabled="formDisabled"
      :rowNumber="true"
      :rowSelection="true"
      :actionButton="true">

      <template v-slot:action="props">
        <a @click="handleDelete(props)">删除</a>
      </template>
    </j-editable-table>
  </a-spin>
</template>

<script>

  import { getAction } from '@/api/manage'
  import { FormTypes,getRefPromise,VALIDATE_NO_PASSED } from '@/utils/JEditableTableUtil'
  import { JEditableTableModelMixin } from '@/mixins/JEditableTableModelMixin'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'SkAreaForm',
    mixins: [JEditableTableModelMixin],
    components: {
    },
    data() {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        model:{
          id: 0,
        },
        // 新增时子表默认添加几行空数据
        addDefaultRowNum: 1,
        validatorRules: {
        },
        refKeys: ['skAreaAcquisitionTime', ],
        tableKeys:['skAreaAcquisitionTime', ],
        activeKey: 'skAreaAcquisitionTime',
        // 区域采集时间
        skAreaAcquisitionTimeTable: {
          loading: false,
          dataSource: [],
          columns: [
            {
              title: '区域采集开始时间',
              key: 'acquisitionStartTime',
              type: FormTypes.time,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '区域采集结束时间',
              key: 'acquisitionEndTime',
              type: FormTypes.time,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
          ]
        },
        url: {
          add: "/management/skArea/saveOutdoorAreaAcquisitionTime",
          skAreaAcquisitionTime: {
            list: '/management/skArea/queryOutdoorAreaAcquisitionTime'
          },
        }
      }
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
    },
    methods: {
      addBefore(){
        this.skAreaAcquisitionTimeTable.dataSource=[]
      },
      addAfter() {
        this.requestSubTableData(this.url.skAreaAcquisitionTime.list, [], this.skAreaAcquisitionTimeTable)
      },
      getAllTable() {
        let values = this.tableKeys.map(key => getRefPromise(this, key))
        return Promise.all(values)
      },
      /** 调用完edit()方法之后会自动调用此方法 */
      editAfter() {
        this.$nextTick(() => {
        })
        // 加载子表数据
        if (this.model.id) {
          let params = { id: this.model.id }
        }
      },
      //校验所有一对一子表表单
      validateSubForm(allValues){
          return new Promise((resolve,reject)=>{
            Promise.all([
            ]).then(() => {
              resolve(allValues)
            }).catch(e => {
              if (e.error === VALIDATE_NO_PASSED) {
                // 如果有未通过表单验证的子表，就自动跳转到它所在的tab
                // this.activeKey = e.index == null ? this.activeKey : this.refKeys[e.index]
              } else {
                console.error(e)
              }
            })
          })
      },
      /** 整理成formData */
      classifyIntoFormData(allValues) {
        let main = Object.assign(this.model, allValues.formValue)
        return {
          ...main, // 展开
          skAreaAcquisitionTimeList: allValues.tablesValue[0].values,
        }
      },
      validateError(msg){
        this.$message.error(msg)
      },

    }
  }
</script>

<style scoped>
</style>